﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Web.UI.WebControls;

using WebSite.Domain;

namespace WebSite.DAL {
    public class ProntuarioDAO 
    {

        public static void ListarProntuarios(ListItemCollection li)
        {
            SqlDataReader dr;
            string strsql = "Select * from tab_Prontuario";
            SqlConnection objConnection = ConnectionFactory.obterConexao();            

            try
            {
                objConnection.Open();
                SqlCommand objCommand = new SqlCommand(strsql, objConnection);
                dr = objCommand.ExecuteReader();

                while (dr.Read())
                {
                    li.Add (new ListItem(dr["Nome"].ToString() + " - " + dr["Descricao"].ToString(), dr["idProntuario"].ToString()));                    
                }

            }
            catch (Exception)
            {
                throw;
            }
            finally
            {                
                objConnection.Close();
            }            
        }


        public static void CadastrarProntuario(WebSite.Domain.Prontuario prontuario)
        {
            string strsql = "INSERT INTO tab_Prontuario(Nome, Descricao, idMedico) values(@Nome,@Descricao,@idMedico)";
            SqlConnection objConnection = ConnectionFactory.obterConexao();
            objConnection.Open();
            SqlCommand objCommand = new SqlCommand(strsql, objConnection);
            objCommand.Parameters.Add(new SqlParameter("@Nome", prontuario.nome));
            objCommand.Parameters.Add(new SqlParameter("@Descricao", prontuario.descricao));
            objCommand.Parameters.Add(new SqlParameter("@idMedico", prontuario.idMedico));
            objCommand.ExecuteNonQuery();
            objConnection.Close();
        }
   





    }
}